package com.turing.selfwebservice.cardholderuser;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.datatype.XMLGregorianCalendar;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.turing.post.webservice.client.AccountSystemAddTradDetail;
import com.turing.post.webservice.client.ActivateCard;
import com.turing.post.webservice.client.CardClassic;
import com.turing.post.webservice.client.CardClassicChangePolicy;
import com.turing.post.webservice.client.CardHolderUser;
import com.turing.post.webservice.client.CardHolderUserLink;
import com.turing.post.webservice.client.ChangeCardClassicObject;
import com.turing.post.webservice.client.ChangeCardClassicResult;
import com.turing.post.webservice.client.CommonWebResult;
import com.turing.post.webservice.client.ExtendExpiredObject;
import com.turing.post.webservice.client.ExtendExpiredResult;
import com.turing.post.webservice.client.IdType;
import com.turing.post.webservice.client.PcpsWebInput;
import com.turing.post.webservice.client.SysOpUser;
import com.turing.selfwebservice.common.BaseServlet;
import com.turing.selfwebservice.common.Config;
import com.turing.selfwebservice.common.OptimalPageControl;
import com.turing.selfwebservice.common.Toolkit;
import com.turing.selfwebservice.util.DateUtil;
import com.turing.selfwebservice.util.Helper;
import com.turing.selfwebservice.util.ServletUtil;

public class CardHolderUserServlet extends BaseServlet {
	/**
	 * 持卡用户基本信息
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward CardHolderUserInfo(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String _url = "cardHolderUserInfo";
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			CardHolderUser cardholderuserinfo = webWscImplPortType
					.getCardHolderUserByCardHolderUserId(cardHolderUserId);
			if (cardholderuserinfo != null) {
				if (cardholderuserinfo.getIdTypeId() != null) {
					IdType type = webWscImplPortType
							.getIdTypeByIdTypeId(cardholderuserinfo
									.getIdTypeId());
					if (type != null)
						request
								.setAttribute("IdTypeName", type
										.getIdTypeName());
				}
			}
			List<IdType> list = webWscImplPortType
					.getIdTypeIdListByCategory("0");
			request.setAttribute("IdTypeList", list);
			request.setAttribute("CardHolderUser", cardholderuserinfo);
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
			_url = "error";
		}
		return mapping.findForward(_url);
	}

	/**
	 * 跟新持卡用户信息
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward UpdateCardHolderUserInfo(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String Name = getParameter(request, "cardusername");
			String sex = getParameter(request, "sex");
			String linkTele = getParameter(request, "linkTele");
			String email = getParameter(request, "email");
			String question1 = getParameter(request, "question1");
			String answer1 = getParameter(request, "answer1");
			String question2 = getParameter(request, "question2");
			String answer2 = getParameter(request, "answer2");
			String question3 = getParameter(request, "question3");
			String answer3 = getParameter(request, "answer3");
			CardHolderUser holderuser = new CardHolderUser();
			holderuser.setCardHolderUserId(cardHolderUserId);
			holderuser.setName(Name);
			holderuser.setSex(sex);
			holderuser.setLinkTele(linkTele);
			holderuser.setEmail(email);
			holderuser.setQuestion1(question1);
			holderuser.setQuestion2(question2);
			holderuser.setQuestion3(question3);
			holderuser.setAnswer1(answer1);
			holderuser.setAnswer2(answer2);
			holderuser.setAnswer3(answer3);
			CommonWebResult commonWebResult = webWscImplPortType
					.updateCardHolderUser(holderuser);
			if (commonWebResult.isSuccess()) {
				request.setAttribute("UpdateMsg", "更新持卡用户信息成功!");
			} else {
				request.setAttribute("UpdateMsg", "更新持卡用户信息失败!");
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		ActionForward af = new ActionForward();
		af.setPath("/cardHolderUserServlet.do?method=CardHolderUserInfo");
		return af;
	}

	/**
	 * 持卡用户 修改密码
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward UpdateCardHolderUserPwd(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String oldpassword = getParameter(request, "oldpassword");
			String newpassword = getParameter(request, "newpassword");
			CardHolderUser cardholderuser = new CardHolderUser();
			cardholderuser.setCardHolderUserId(cardHolderUserId);
			cardholderuser.setLogonName(cardHolderUserLogonName);
			cardholderuser.setLogonPasswd(oldpassword);
			CommonWebResult resultString = webWscImplPortType
					.changeCardHolderUserPwd(cardholderuser, newpassword);
			if (resultString.isSuccess()) {
				request.setAttribute("UpdateMsg", "修改用户密码成功!");
			} else {
				request.setAttribute("UpdateMsg", resultString
						.getExcepMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		ActionForward af = new ActionForward();
		af.setPath("/cardHolderUserServlet.do?method=CardHolderUserInfo");
		return af;
	}

	/**
	 * 卡关联信息
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward CardHolderUserLinkIndex(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String _url = "cardHolderUserLinkIndex";
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			CardHolderUser cardHolderUserInfo = webWscImplPortType
					.getCardHolderUserByCardHolderUserId(cardHolderUserId);
			request.setAttribute("CardHolderUser", cardHolderUserInfo);
			List<CardHolderUserLink> cardHolderUserLinks = webWscImplPortType
					.getCardHolderUserLinksByCardHolderUserId(cardHolderUserId);
			request.setAttribute("CardHolderUserLinks", cardHolderUserLinks);
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
			_url = "error";
		}
		return mapping.findForward(_url);
	}

	/**
	 * 卡信息
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward ActiviteCardInfo(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String cardNo = getParameter(request, "cardNo");
			if (null == cardNo) {
				response.getWriter().write("卡号不允许为空!");
				return null;
			}
			ActivateCard ac = webWscImplPortType
					.getActivateCardByCardNo(cardNo);
			if (ac != null) {
				CardClassic ccvo = webWscImplPortType
						.getCardClassicByCardClassicId(ac.getCardClassicId());
				String cardClassicName = ccvo.getCardClassicName();
				String expired = "";
				if (null != ac.getExpired())
					expired = DateUtil.getStringByXMLGregorianCalendar(ac
							.getExpired());
				ActiveCardObj activeCardObj = new ActiveCardObj(ServletUtil
						.changeF2Y(ac.getBalance().toString()), expired,
						cardClassicName, ac.getCardClassicId().toString());
				String s = Helper.JSON_Bean2String(activeCardObj);
				response.getWriter().write(s);
				return null;
			}
			response.getWriter().write("false");
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return null;
	}

	/**
	 * 卡延期操作
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward CardExtendExpired(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String cardNo = getParameter(request, "cardNo");
			String remark = getParameter(request, "remark");
			String expired = getParameter(request, "expired");
			String isTrail = getParameter(request, "isTrail");
			if (ServletUtil.isEmpty(remark))
				remark = "持卡用户 [ " + cardHolderUserLogonName + " ]卡延期操作";
			if (ServletUtil.getStringLength(remark) > 255) {
				response.getWriter().write("error: 备注信息长度不能超过255个字符");
				return null;
			}
			if (null == cardNo) {
				response.getWriter().write("error: 卡号不允许为空!");
				return null;
			}
			boolean isTrailb = true;
			if (isTrail != null && isTrail.equals("true")) {
				isTrailb = true;
			} else {
				isTrailb = false;
			}
			XMLGregorianCalendar sExpired;
			if (expired != null) {
				sExpired = DateUtil.getXMLGregorianCalendarByDate(DateUtil
						.getDateYMDByString(expired));
			} else {
				sExpired = DateUtil.getXMLGregorianCalendarByDate(new Date());
			}
			ActivateCard ao = webWscImplPortType
					.getActivateCardByCardNo(cardNo);
			if (ao == null) {
				response.getWriter().write("false");
				return null;
			}
			SysOpUser opUser = webWscImplPortType
					.getInternetAgentSysOpUserByCardNo(cardNo);
			if (null == opUser || null == opUser.getOperId()
					|| "".equals(opUser.getOperId())) {
				response.getWriter().write("error: 获取代理操作员失败!");
				return null;
			}
			ExtendExpiredObject eeobj = new ExtendExpiredObject();
			eeobj.setCardNo(cardNo);
			eeobj.setOperId(opUser.getOperId());
			eeobj.setRemark(remark);
			eeobj.setNewExpired(sExpired);
			eeobj.setPaidFee(true);// 执行扣费,false不扣费
			eeobj.setIsTrail(isTrailb);// true试算返回结果. false执行卡延期操作并扣费.
			ExtendExpiredResult result = webWscImplPortType
					.cardExtendExpired(putwebinput,eeobj);
			ExtendExpiredObject resultObj = result.getExtendExpiredObject();
			if (result.isSuccess() && resultObj != null) {
				resultObj.setStrExpired(DateUtil
						.getStringByXMLGregorianCalendar(resultObj
								.getNewExpired()));
				resultObj.setNewExpired(null);
				resultObj.setBalance(resultObj.getBalance());
				if (isTrailb == true) {
					String s = Helper.JSON_Bean2String(resultObj);
					response.getWriter().write(s);
					return null;
				} else if (isTrailb == false) {
					String s = Helper.JSON_Bean2String(resultObj);
					response.getWriter().write(s);
					return null;
				}
			} else {
				response.getWriter()
						.write("error: " + result.getExcepMessage());
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return null;
	}

	/**
	 * 获取卡种类列表
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward GetCardClassicChangeList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			BigInteger fromCardClassicId = new BigInteger(getParameter(request,
					"fromCardClassicId"));
			List<CardClassicChangePolicy> list = webWscImplPortType
					.getCardClassicChangePolicyListByFromClassicId(fromCardClassicId);
			List<CardClassicChangePolicyObj> toCardClassicNamelList = new ArrayList<CardClassicChangePolicyObj>();
			CardClassicChangePolicyObj obj = null;
			CardClassicChangePolicy vo = null;
			for (int i = 0; i < list.size(); i++) {
				vo = list.get(i);
				obj = new CardClassicChangePolicyObj();
				CardClassic card = webWscImplPortType
						.getCardClassicByCardClassicId(vo.getToClassicId());
				obj.setToClassicId(vo.getToClassicId());
				obj.setToClassicName(card.getCardClassicName());
				toCardClassicNamelList.add(obj);
			}
			String s = Helper.JSON_List2String(toCardClassicNamelList);
			response.getWriter().write(s);
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return null;
	}

	/**
	 * 获取变更卡种类手续费
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward GetChangeFee(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String fromCardClassicId = getParameter(request,
					"fromCardClassicId");
			String toCardClassicId = getParameter(request, "toCardClassicId");
			String cardNo = getParameter(request, "cardNo");
			if (toCardClassicId.equals("-1")) {
				response.getWriter().write("error:请选择变更卡种类!");
				return null;
			}
			CardClassicChangePolicy policy = new CardClassicChangePolicy();
			policy.setFromClassicId(new BigInteger(fromCardClassicId));
			policy.setToClassicId(new BigInteger(toCardClassicId));
			CardClassicChangePolicy cardPolicy = webWscImplPortType
					.getCardClassicChangePolicyByPK(policy);
			String feeType = cardPolicy.getFeeType();
			String pay = "";
			if (feeType.equals("0")) {
				pay = cardPolicy.getFixedFee().toString();
			}
			if (feeType.equals("1")) {
				ActivateCard ao = webWscImplPortType
						.getActivateCardByCardNo(cardNo);
				BigInteger balance = ao.getBalance();
				Integer feeRatio = cardPolicy.getFixedFeeRatio();
				pay = balance.multiply(new BigInteger(feeRatio.toString()))
						.divide(new BigInteger("10000")).toString();
			}
			response.getWriter().write(pay);
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return null;
	}

	/**
	 * 处理变更卡种类操作
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward DoCardClassicChange(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String cardNo = getParameter(request, "cardNo");
			String cardClassicId = getParameter(request, "toCardClassicId");
			String password = getParameter(request, "password");
			String remark = getParameter(request, "remark");
			String isTrail = getParameter(request, "isTrail");
			if (ServletUtil.isEmpty(cardNo)) {
				response.getWriter().write("error: 卡号不能为空");
				return null;
			}
			if (cardClassicId == "-1") {
				response.getWriter().write("error: 请选择变更卡种类!");
				return null;
			}
			if (ServletUtil.isEmpty(password)) {
				response.getWriter().write("error: 密码不能为空");
				return null;
			}
			if (ServletUtil.isEmpty(remark)) {
				remark = "持卡用户 [ " + cardHolderUserLogonName + " ] 变更卡种类";
			}
			if (ServletUtil.getStringLength(remark) > 255) {
				response.getWriter().write("error: 备注信息长度不能超过255个字节.");
				return null;
			}
			ChangeCardClassicObject cardObj = new ChangeCardClassicObject();
			SysOpUser opUser = webWscImplPortType
					.getInternetAgentSysOpUserByCardNo(cardNo);
			if (null == opUser || null == opUser.getOperId()
					|| "".equals(opUser.getOperId())) {
				response.getWriter().write("error: 获取代理操作员失败!");
				return null;
			}
			boolean isTrailb = true;
			if (isTrail != null && isTrail.equals("true")) {
				isTrailb = true;
			} else {
				isTrailb = false;
			}
			cardObj.setNewCardClassicId(new BigInteger(cardClassicId));
			cardObj.setCardNo(cardNo);
			cardObj.setOperId(opUser.getOperId());
			cardObj.setPaidFee(true);
			cardObj.setPwd(password);
			cardObj.setChargeMode("1");
			cardObj.setIsTrial(isTrailb);
			cardObj.setRemark(remark);
			ChangeCardClassicResult result = webWscImplPortType
					.changeCardClassic(putwebinput,cardObj);
			if (result.isSuccess()) {
				String s = Helper.JSON_Bean2String(result
						.getChangeCardClassicObject());
				response.getWriter().write(s);
			} else {
				response.getWriter()
						.write("error: " + result.getExcepMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return null;
	}

	/**
	 * 卡余额查询
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward GetCardBalance(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String cardNo = getParameter(request, "cardNo");
			if (ServletUtil.isEmpty(cardNo)) {
				response.getWriter().write("error:卡号获取失败!");
				return null;
			}
			ActivateCard activateCard = webWscImplPortType
					.getActivateCardByCardNo(cardNo);
			if (null == activateCard) {
				response.getWriter().write("error:获取卡信息失败!");
				return null;
			}
			response.getWriter().write(activateCard.getBalance().toString());
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return null;
	}

	/**
	 * 卡改密
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward ChangeCardPassword(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String cardNo = getParameter(request, "cardNo");
			if (ServletUtil.isEmpty(cardNo)) {
				response.getWriter().write("卡号获取失败!");
				return null;
			}
			String oldPwd = getParameter(request, "oldCardPwd");
			String newPwd = getParameter(request, "newCardPwd");
			String remark = getParameter(request, "ccpRemark");
			if (ServletUtil.isEmpty(remark))
				remark = "持卡用户 [ " + cardHolderUserLogonName + " ] 卡改密";
			SysOpUser opUser = webWscImplPortType
					.getInternetAgentSysOpUserByCardNo(cardNo);
			if (null == opUser) {
				response.getWriter().write("获取代理操作员失败");
				return null;
			}
			BigInteger operId = opUser.getOperId();
			CommonWebResult commonWebResult = webWscImplPortType
					.changeCardPassword(putwebinput,cardNo, oldPwd, newPwd, operId, remark);
			if (commonWebResult.isSuccess()) {
				response.getWriter().write("true");
				return null;
			} else {
				response.getWriter().write(commonWebResult.getExcepMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return null;
	}

	/**
	 * 子账户交易明细
	 */
	public ActionForward CardTradDetail(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String _url = "cardTradDetail";
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String cardNo = getParameter(request, "cardNo");
			String startTranDate = getParameter(request, "startTranDate");
			String endTranDate = getParameter(request, "endTranDate");
			SysOpUser sysOpUser = webWscImplPortType
					.getInternetAgentSysOpUserByCardNo(cardNo);
			PcpsWebInput webInput = new PcpsWebInput();
			if (null != sysOpUser && null != sysOpUser.getOperId()) {
				webInput.setOperId(sysOpUser.getOperId());
				webInput.setOperBranchNo(sysOpUser.getOperBranchNo());
			}
			request.setAttribute("cardNo", cardNo);
			// 子账户不为空时执行交易明细的查询
			if (!ServletUtil.isEmpty(startTranDate)
					&& !ServletUtil.isEmpty(endTranDate)) {
				BigInteger total = webWscImplPortType
						.getAccountSystemAddTradDetailTotalByCondition(
								webInput, cardNo, startTranDate, endTranDate);
				if (null == total)
					total = BigInteger.ZERO;
				int pgNo = getIntParameter(request, "pageNo", 1);
				int pgCount = Integer.parseInt(String.valueOf(total));
				List<AccountSystemAddTradDetail> datas = webWscImplPortType
						.getAccountSystemAddTradDetailByCondition(webInput,
								cardNo, startTranDate, endTranDate, pgNo - 1);

				if (null != datas) {
					// 子账户交易明细列表
					List<AccountTradDetailObj> accountTradDetailObjs = new ArrayList<AccountTradDetailObj>();
					for (AccountSystemAddTradDetail data : datas) {
						String tranTime = Toolkit.dateTostring(Toolkit
								.convertToDate(data.getTranTime()));
						AccountTradDetailObj obj = new AccountTradDetailObj();
						obj.setTranTime(tranTime);
						obj.setTranType(data.getTranType());
						obj.setDebitAmount(ServletUtil.changeF2Y(data
								.getDebitAmount().toString()));
						obj.setCreditAmount(ServletUtil.changeF2Y(data
								.getCreditAmount().toString()));
						BigInteger balance = data.getMasBalance() == null ? BigInteger.ZERO
								: data.getMasBalance();
						obj.setBalance(ServletUtil
								.changeF2Y(balance.toString()));
						obj.setRemark(data.getRemark());
						accountTradDetailObjs.add(obj);
					}
					request.setAttribute("accountTradDetailObjs",
							accountTradDetailObjs);
				}
				// 封装分页查询对象
				OptimalPageControl opg = new OptimalPageControl(
						Config.PAGE_SIZE, pgNo, pgCount);
				// 组装分页组件的请求URL
				String pageUrl = "cardHolderUserServlet.do?method=CardTradDetail&cardNo="
						+ cardNo;
				if (!ServletUtil.isEmpty(startTranDate))
					pageUrl += "&startTranDate=" + startTranDate;
				if (!ServletUtil.isEmpty(endTranDate))
					pageUrl += "&endTranDate=" + endTranDate;
				request.setAttribute("pageInfo", opg);// 翻页参数
				request.setAttribute("servletPath", pageUrl);// 翻页路径
				_url = "cardTradDetail";
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
			_url = "error";
		}
		return mapping.findForward(_url);
	}

	/**
	 * 添加关联卡信息
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward AddCardHoldUserLink(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ActionForward af = new ActionForward();
		af.setPath("/cardHolderUserServlet.do?method=CardHolderUserLinkIndex");
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String cardNo = getParameter(request, "cardNo");
			String cardPwd = getParameter(request, "cardPwd");

			CardHolderUserLink cardHolderUserLink = new CardHolderUserLink();
			cardHolderUserLink.setCardHolderUserId(cardHolderUserId);
			cardHolderUserLink.setCardNo(cardNo);
			CommonWebResult commonWebResult = webWscImplPortType
					.insertCardHolderUserLink(cardHolderUserLink, cardPwd);
			if (commonWebResult.isSuccess()) {
				request.setAttribute("ReturnMsg", "添加关联卡成功");
			} else {
				request.setAttribute("ReturnMsg", commonWebResult
						.getExcepMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return af;
	}

	/**
	 * 取消关联卡
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward CancelCardHoldUserLink(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ActionForward af = new ActionForward();
		af.setPath("/cardHolderUserServlet.do?method=CardHolderUserLinkIndex");
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String cardNo = getParameter(request, "cardNo");
			CardHolderUserLink cardHolderUserLink = new CardHolderUserLink();
			cardHolderUserLink.setCardHolderUserId(cardHolderUserId);
			cardHolderUserLink.setCardNo(cardNo);
			CommonWebResult commonWebResult = webWscImplPortType
					.cancelCardHolderUserLink(cardHolderUserLink);
			if (commonWebResult.isSuccess()) {
				request.setAttribute("ReturnMsg", "取消关联卡成功");
			} else {
				request.setAttribute("ReturnMsg", commonWebResult
						.getExcepMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return af;
	}

	/**
	 * 卡临时挂失
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward CardTemporaryLoss(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			if (webWscImplPortType == null)
				returnError(mapping, request);
			String cardNo = getParameter(request, "cardNo");
			if (ServletUtil.isEmpty(cardNo)) {
				response.getWriter().write("卡号获取失败!");
				return null;
			}
			String remark = getParameter(request, "remark");
			if (ServletUtil.isEmpty(remark))
				remark = "持卡用户 [ " + cardHolderUserLogonName + " ] 临时挂失";
			SysOpUser opUser = webWscImplPortType
					.getInternetAgentSysOpUserByCardNo(cardNo);
			if (null == opUser) {
				response.getWriter().write("获取代理操作员失败");
				return null;
			}
			PcpsWebInput webInput = new PcpsWebInput();
			webInput.setOperId(opUser.getOperId());
			webInput.setOperBranchNo(opUser.getOperBranchNo());
			CommonWebResult commonWebResult = webWscImplPortType
					.cardTemporaryLoss(webInput, cardNo, remark);
			if (commonWebResult.isSuccess()) {
				response.getWriter().write("true");
				return null;
			} else {
				response.getWriter().write(commonWebResult.getExcepMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnError(mapping, request);
		}
		return null;
	}
}